﻿using System;
using System.Collections;
using FlowCanvas;
using FlowCanvas.Nodes;
using NodeCanvas.Framework;
using ParadoxNotion.Design;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    [Category("Ggame")]
    public class BeginDeckGuideClick  : CallableActionNodeBase
    {
        private int heroId;
        
        public static Action<int> OnHeroOnDeckSuccess;
        
        public FlowOutput onComplete;
        
        public void Invoke(int heroId)
        {
            BlueprintUtils.BeginDeckGuideClick(heroId);
            OnHeroOnDeckSuccess += HeroOnDeckSuccess;
        }
        
        private void HeroOnDeckSuccess(int id)
        {
            if (heroId == id)
            {
                BlueprintUtils.DeckGuideClickSuccess(id);
                onComplete?.Call(new Flow());
            }
        }
        
        protected override void OnRegisterPorts(FlowNode node)
        {
            var p1 = node.AddValueInput<int>("heroId");
            node.AddFlowInput("In", (Flow f) =>
            {
                heroId = p1.value;
                Invoke(p1.value);
            });
            
            onComplete = node.AddFlowOutput("onComplete");
        }

        public override void OnGraphStoped()
        {
            base.OnGraphStoped();
            OnHeroOnDeckSuccess -= HeroOnDeckSuccess;
        }
    }
}